package com.example.myapplication;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.example.myapplication.logs.LogDatabase;
import com.example.myapplication.logs.PowerEvent;

import java.util.concurrent.Executors;

public class ShutdownReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (Intent.ACTION_SHUTDOWN.equals(intent.getAction())) {
            PowerEvent event = new PowerEvent();
            event.timestamp = System.currentTimeMillis();
            event.type = "shutdown";
            Executors.newSingleThreadExecutor().execute(() ->
                    LogDatabase.get(context).logDao().insertPower(event)
            );
        }
    }
}
















